//
// Created by 下次一定 on 2021/9/22.
//
/*
 * 01背包
 * */

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1010;

// n是物品的数量  m是重量
int n, m;
//v value   w weight
int v[N], w[N];
int f[N][N];
//一维
int of[N];

int main() {
    cin >> n >> m;

    for (int i = 1; i <= n; i++)cin >> v[i] >> w[i];

    // f[0][0~m] = 0
    for (int i = 1; i <= n; i++) {
       /* for (int j = 0; j <= m; j++) {
            // 含不含第i个物品
            //不含i
            f[i][j] = f[i - 1][j];
            //含有i
            if (j >= w[i]) f[i][j] = max(f[i][j], f[i - 1][j - v[i]] + v[i]);
        }*/

       for(int j = m; j >= v[i]; j++){
           of[j] = max(of[j],of[j - w[i]] + v[i]);
       }
    }
    cout << f[n][m] << endl;

}